package hot100;

public class f4_搜索二维矩阵II {
    public boolean searchMatrix(int[][] matrix, int target) {
        for(int[] row : matrix){
            int index = search(row, target);
            if(index >= 0){
                return true;
            }
        }
        return false;
    }
    public int search(int[] nums, int target) {
        int low = 0;
        int high = nums.length - 1;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (nums[mid] == target) {
                return mid;
            }else if (nums[mid] > target) {
                high = mid - 1;
            }else {
                low = mid + 1;
            }
        }
        return -1;
    }
}
